package com.umgsai.thread.thread45;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Service {
	private Lock lock = new ReentrantLock();
	public void methodA() {
		try {
			lock.lock();
			System.out.println("methodA begin " + Thread.currentThread().getName() + " time=" + System.currentTimeMillis());
			Thread.sleep(5000);
			System.out.println("methodA end " + Thread.currentThread().getName() + " time=" + System.currentTimeMillis());
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			lock.unlock();
		}
	}
	public void methodB() {
		try {
			lock.lock();
			System.out.println("methodB begin " + Thread.currentThread().getName() + " time=" + System.currentTimeMillis());
			Thread.sleep(5000);
			System.out.println("methodB end " + Thread.currentThread().getName() + " time=" + System.currentTimeMillis());
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			lock.unlock();
		}
	}
}
